<template>
<div class="out-row">
	<div class="fields-bottom-input" v-if="fieldsObj.type">
		<p v-if="!fieldsObj.settings.value" class="input-tips">
			开始时间
		</p>
		<p v-else class="input-content">
			{{ getTime(fieldsObj.settings.value, 0) }}
		</p>
        <i class="el-icon-date"></i>
	</div>

  <div class="fields-bottom-input" v-if="fieldsObj.type">
		<p v-if="!fieldsObj.settings.value" class="input-tips">
			结束时间
		</p>
		<p v-else class="input-content">
			{{ getTime(fieldsObj.settings.value, 1) }}
		</p>
    <i class="el-icon-date"></i>
	</div>

</div>
</template>

<script>
import dayjs from 'dayjs'

export default {
  name: 'CTimeRange',
  props: {
    fields: {
      default: () => {
        return {}
      },
    },
  },
  watch: {
    'fields': {
      handler (val) {
        this.fieldsObj = val
      },
      deep: true,
      immediate: true
    }
  },
  data () {
    return {
      fieldsObj: {}
    }
  },
  methods: {
    getTime (data, num) {
      return data && data.length ? this.formatShowTime(this.fieldsObj.settings.format, data[num]) : data
    },
    formatShowTime (format, value) {
      if (!value) {
        return ''
      }
      let fm = format.replace('yyyy', 'YYYY')
      return dayjs(value).format(fm)
    },
  },
  mounted () {
    this.fieldsObj = this.fields
  }
}
</script>

<style lang="less" scoped>
.input-tips {
  color: #CBCFD6;
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
}

.fields-bottom-input {
    position: relative;
    flex: 1;
    margin-right: 44px;
    &:last-child {
      margin-right: 0;
    }
    .el-icon-date {
        position: absolute;
        right: 12px;
        top: 0;
        bottom: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
    }
}
.out-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
</style>
